package com.example.ormsqlsplicingframe1;

import com.alibaba.druid.pool.DruidDataSource;
import com.example.ormsqlsplicingframe1.proxy.RouteSession;
import com.example.ormsqlsplicingframe1.session.BaseSession;
import com.example.ormsqlsplicingframe1.session.ProxySession;
import com.example.ormsqlsplicingframe1.session.SessionUtil;
import com.example.ormsqlsplicingframe1.utlis.ProxySessionUtils;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;

import javax.sql.DataSource;
import java.util.HashMap;

@SpringBootApplication
public class OrmSqlSplicingFrame1Application {




    @Bean
    public BaseSession session(DataSource dataSource){
        DruidDataSource source = new DruidDataSource();
        source.setDriverClassName("com.mysql.cj.jdbc.Driver");
        source.setUrl("jdbc:mysql://localhost:3306/sys?serverTimezone=GMT%2B8&useUnicode=true&reWriteBatchedInserts=true&characterEncoding=utf8&rewriteBatchedStatements=true&useSSL=false&allowMultiQueries=true");
        source.setUsername("root");
        source.setPassword("123456");
        HashMap<String, DataSource> map = new HashMap<>();
        map.put("user",source);

        BaseSession session = new ProxySession(dataSource);
        SessionUtil.setSession(session);
        session.setDatasource(map);
        return session;
    }

    @Bean
    public ProxySessionUtils proxySession(){
       return new ProxySessionUtils(new RouteSession());
    }

    public static void main(String[] args) {
        SpringApplication.run(OrmSqlSplicingFrame1Application.class, args);
    }

}

